package com.easywan.util;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class  HttpsUtils{
	 public static String doGet(String url,String cookie) throws Exception {
	        // 鍒涘缓Httpclient瀵硅薄
	        CloseableHttpClient httpclient = HttpClients.createDefault();

	        // 鍒涘缓http GET璇锋眰
	        HttpGet httpGet = new HttpGet(url);
	        httpGet.setHeader( "User-Agent",
	                "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36");
	        if(cookie != null)
	        	httpGet.setHeader("Cookie",cookie);//"cna=iCjlEf4SY3YCAa+/EZeETPAS; isg=Au7uNc0QO7mYYU_dJBccQB5BPkRwR7OH7WWpiBi3W_Gs-49VgH66-SS7xVzp; WHOIS_JSESSIONID=31666Z71-KGAM3UQ7NCD0X05CX1JS2-RQBGUU4J-19JL; whoistmp0=eNrzEHAMDfGId%2FH3dfT0i%2Fdz9HXlSU0srixPzNPLzEvL5w12DQ729PeL9%2FV3cfUxiKrOTLFSMjY0MzOLMjfU9XZ39DUODTT3c3YxiDAwdY4w9Ao20g0KdHIPDTXx0jW09PJR0kkusTI0sbQ0sTQ0tjAyMzHWSUyGC1gCoZFOboWVQW0UALTuJZs%3D; aliyun_choice=CN");	
	        CloseableHttpResponse response = null;
	        try {
	            // 鎵ц璇锋眰
	            response = httpclient.execute(httpGet);
	            // 鍒ゆ柇杩斿洖鐘舵�佹槸鍚︿负200
	            if (response.getStatusLine().getStatusCode() == 200) {
	            	//System.out.println(EntityUtils.toString(response.getEntity(), "UTF-8"));
	                return EntityUtils.toString(response.getEntity(), "UTF-8");
	            }
	        } finally {
	            if (response != null) {
	                response.close();
	            }
	            // 鐩稿綋浜庡叧闂祻瑙堝櫒
	            httpclient.close();
	        }
	        return null;
	    }
}
